<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function queryData(url) {
      const p = new Promise(function(resolve, reject) {
        const xhr = new XMLHttpRequest()
        xhr.open('get', url)
        xhr.send()

        xhr.onreadystatechange = function() {
          if( xhr.readyState !== 4 ) { return }
          if( xhr.readyState === 4 && xhr.status === 200 ) {
            resolve(xhr.responseText)
          } else {
            reject('服务器有问题')
          }
        }
      })
      return p
    }

    const p = queryData('http://127.0.0.1:3000/data')
    const p1 = queryData('http://127.0.0.1:3000/data1')
    const p2 = queryData('http://127.0.0.1:3000/data2')

    // all： 全部  全部都结束， 才执行回调函数
    Promise.all([p, p1, p2])
      .then( res=> console.log( res ))

    // race 竞赛 赛跑
    // Promise.race([p, p1, p2])
    //   .then( res=> console.log( res ))


  </script>
</body>

</html>